<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
	layout:decorator="layout/default">
<head lang="en">
<title>Your profile</title>
</head>
<body>
	<div class="row" layout:fragment="content">

		<h2 class="indigo-text center" th:text="#{profile.title}">Personal
			info</h2>

		<div class="row">

			<div class="col m8 s12 offset-m2">
				<img th:src="@{/uploadedPicture}" width="100" height="100" />
			</div>

			<div class="col s12 center red-text" th:text="${error}"
				th:if="${error}">Error during upload</div>

			<form th:action="@{/register}" method="post"
				enctype="multipart/form-data" class="col m8 s12 offset-m2">

				<div class="input-field col s6">
					<input type="file" id="file" name="file" />
				</div>

				<div class="col s6 center">
					<button class="btn indigo waves-effect waves-light" type="submit"
						name="upload" th:text="#{upload}">
						Upload <i class="mdi-content-send right"></i>
					</button>
				</div>
			</form>
		</div>
		<!-- 
		<div class="row">
			<div class="col m8 s12 offset-m2">
				<img alt="your" th:src="@{/uploadedPicture}" width="100"
					height="100" />
			</div>
			<form th:action="@{/register}" method="post"
				enctype="multipart/form-data" class="col m8 s12 offset-m2">
				<div class="input-field col s6">
					<input type="file" id="file" name="file" />
				</div>
				<div class="col s6 center">
					<button class="btn indigo waves-effect waves-light" type="submit"
						name="upload" th:text="#{upload}">
						Upload <i class="mdi-content-send right"></i>
					</button>
				</div>
			</form>
		</div>
		 -->
		<!-- 
		<div class="row">

			<div class="col m8 s12 offset-m2">
				<img th:src="@{/uploadedPicture}" width="100" height="100" />
			</div>

			<div class="col s12 center red-text" th:text="${error}"
				th:if="${error}">Error during upload</div>

			<form th:action="@{/profile}" method="post"
				enctype="multipart/form-data" class="col m8 s12 offset-m2">

				<div class="input-field col s6">
					<input type="file" id="file" name="file" />
				</div>

				<div class="col s6 center">
					<button class="btn indigo waves-effect waves-light" type="submit"
						name="upload" th:text="#{upload}">
						Upload <i class="mdi-content-send right"></i>
					</button>
				</div>
			</form>
		</div>
 -->

		<form th:action="@{/register}" th:object="${profileForm}"
			method="post" class="col m8 s12 offset-m2">
			<!-- 
			<ul th:if="${#fields.hasErrors('*')}" class="errorlist">
				<li th:each="err:${#fields.errors('*')}" th:text="${err}">Input
					is incorrect</li>
			</ul>
			 -->
			<div class="row">
				<div class="input-field col s6">
					<input th:field="${profileForm.name}" id="name" type="text"
						required="required" th:errorclass="invalid" /> <label for="name"
						th:text="#{user.name}">Name</label>
					<div th:errors="*{name}" class="red-text">Error</div>
				</div>
				<div class="input-field col s6">
					<input th:field="${profileForm.email}" id="email" type="email"
						required="required" th:errorclass="invalid" /> <label for="email"
						th:text="#{email}">Email</label>
					<div th:errors="*{email}" class="red-text">Error</div>
				</div>
			</div>
			<div class="row">
				<div class="input-field col s6">
					<input th:field="${profileForm.birthdate}" id="birthdate"
						type="text" required="required" th:errorclass="invalid"
						th:placeholder="${dateFormat}" /> <label for="birthdate"
						th:text="#{birthdate}">Birth Date</label>
					<div th:errors="*{birthdate}" class="red-text">Error</div>
				</div>
			</div>

			<fieldset class="row">
				<legend th:text="#{interests.legend}">What do you like?</legend>
				<button class="btn teal" type="submit" name="addTaste"
					th:text="#{add.interest}">
					Add taste <i class="mdi-content-add left"></i>
				</button>

				<div th:errors="*{interests}" class="red-text">Error</div>

				<div class="row" th:each="row,rowStat : *{interests}">
					<div class="col s6">
						<input type="text" required="required"
							th:field="*{interests[__${rowStat.index}__]}"
							th:placeholder="#{interest.placeholder}" />
					</div>

					<div class="col s6">
						<button class="btn red" type="submit" name="removeInterest"
							th:value="${rowStat.index}" th:text="#{remove}">
							Remove <i class="mdi-action-delete right waves-effect"></i>
						</button>
					</div>
				</div>
			</fieldset>

			<div class="row s12 center">
				<button class="btn indigo waves-effect waves-light" type="submit"
					name="save" th:text="#{submit}">
					Submit <i class="mdi-content-send right"></i>
				</button>
			</div>
		</form>
	</div>
	<script layout:fragment="script">
		$('button').bind('click', function(e) {
			if (e.currentTarget.name === 'save') {
				$(e.currentTarget.form).removeAttr('novalidate');
			} else {
				$(e.currentTarget.form).attr('novalidate', 'novalidate');
			}
		});
	</script>
</body>
</html>
